<?php
/**
 * Created by PhpStorm.
 * User: MSQ
 * Date: 2021/9/24
 * Time: 14:27
 */

namespace App\Utils;


use App\Task\SocketTask;
use App\Task\WebSocketTask;
use Google\Protobuf\Internal\Message;


class TaskHelp
{
    /**
     * 异步websocket方法
     * @param string $action
     * @param array $data
     */
    private static function asyncWebSocketTask(string $action, array $data)
    {
        $task = \EasySwoole\EasySwoole\Task\TaskManager::getInstance();
        $task->async(new WebSocketTask($action, $data));
    }

    /**
     * 异步通知白友
     * @param int $projectId
     * @param string $msgType
     * @param $content
     */
    public static function asyncSend2ByTask(int $projectId, string $msgType, $content)
    {
        self::asyncWebSocketTask('send2By', [
            'projectId' => $projectId,
            'msgType' => $msgType,
            'content' => $content,
        ]);
    }

    /**
     * 异步通知白友
     * @param int $projectId
     * @param string $msgType
     * @param $content
     */
    public static function asyncSend2CallScreenTask(int $projectId, string $msgType, $content)
    {
        self::asyncWebSocketTask('send2CallScreen', [
            'projectId' => $projectId,
            'msgType' => $msgType,
            'content' => $content,
        ]);
    }
}
